package com.rabbitmq.demo.autoack;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Profile(value="autoack")
@Configuration
public class RabbitMQConfig {

    @Bean
    public Queue queue(){
        return new Queue("queue");
    }

    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange("direct.exchange");
    }

    @Bean
    public Binding binding(DirectExchange directExchange,Queue queue){
        return BindingBuilder.bind(queue).to(directExchange).withQueueName();
    }

    @Profile(value="sender")
    @Bean
    public Sender sender(){
        return new Sender();
    }

    @Profile(value="receiver")
    @Bean
    public Receiver receiver(){
        return new Receiver();
    }
}
